package com.cbd.exception;

import cn.dev33.satoken.exception.SaTokenException;
import com.cbd.util.ResultResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: xue
 * @Date: 2024/11/25 17:28
 * @Description:SaToken异常处理器
 */
@ControllerAdvice
@Slf4j
public class SaTokenExceptionHandler {

    @ExceptionHandler(SaTokenException.class)
    @ResponseBody
    public ResultResponse<String> handleSaTokenException(SaTokenException e) {
        log.error("SaTokenException", e);
        //自定义异常处理，返回自定义错误信息
        return ResultResponse.fail("对不起！您暂时没有权限");
    }
}
